local function go_to_other_side()
	local node = vim.treesitter.get_node();

	if not node then return end

	local node_start_row, node_start_col, node_end_row, node_end_col = node:range();
	local node_start_cur_row = node_start_row + 1
	local node_start_cur_col = node_start_col
	local node_end_cur_row = node_end_row + 1
	local node_end_cur_col;
	if node_end_col == 0 then
		node_end_cur_col = 0
	else
		node_end_cur_col = node_end_col - 1
	end

	local cur_row, cur_col = unpack(vim.api.nvim_win_get_cursor(0));

	local target_row, target_col;

	if cur_row == node_end_cur_row and cur_col == node_end_cur_col then
		target_row = node_start_cur_row;
		target_col = node_start_cur_col;
	else
		target_row = node_end_cur_row;
		target_col = node_end_cur_col;
	end

	vim.api.nvim_win_set_cursor(0, { target_row, target_col });
end

-- bind to <M-o> because it's similar to v_o
vim.keymap.set('n', '<M-o>', go_to_other_side, { noremap = true, silent = true });
